import router from "@/router";
// import requestApi from "@/request/requestApi";
import {Message} from "element-ui";

// import 'nprogress/nprogress.css' // progress bar style

// NProgress.configure({ showSpinner: false }) // NProgress Configuration

router.beforeEach(async (to,from,next)=>{
  if(to.query.token){
    localStorage.token = to.query.token
    const _path = to.path
    const _query = to.query
    delete _query.token
    next({
      path:_path,
      query:_query
    })
    // console.log(localStorage.token);
    // if (localStorage.token === '') {
    //   next(false)
    // } else {
    //   next()
    // }
  }else{
    //跳转至临时登录页
    if (to.path === '/'){
      next()
    }else if(localStorage.getItem('token') || to.path.includes('login1') || to.path === '/traceability' || to.path === '/loginXS'){
      next()
    }else {
      next('login1')
    }
/*    if (to.meta.title) {
      document.title = to.meta.title
    }else{
      document.title = '蜂巢动力 - '
    }*/
    // next()
  }
/*  if(localStorage.getItem('token') !== null){
    next()
  }else {
    next()
  }*/
})
//
function checkPermissionPcmManager(){
  const paths = ['settingcenter','riskManage']
  const pagePath = location.href
  paths.forEach(v=>{
    if(pagePath.toLowerCase().includes(v.toLowerCase())
      &&
      !JSON.parse(sessionStorage.productionEnable)){
      Message.error('无权限。')
      router.replace('/login')
    }
  })
}


router.afterEach(() => {
  // finish progress bar
  // NProgress.done()
  // console.log(router.app.$options.store.getters['productionEnable']);
  // checkPermissionPcmManager()
})
